1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module glib.StrvBuilder;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import glib.c.functions;
30 public  import glib.c.types;
31 private import linker.Loader;
32 
33 
34 /**
35  * #GStrvBuilder is a method of easily building dynamically sized
36  * NULL-terminated string arrays.
37  * 
38  * The following example shows how to build a two element array:
39  * 
40  * |[<!-- language="C" -->
41  * g_autoptr(GStrvBuilder) builder = g_strv_builder_new ();
42  * g_strv_builder_add (builder, "hello");
43  * g_strv_builder_add (builder, "world");
44  * g_auto(GStrv) array = g_strv_builder_end (builder);
45  * ]|
46  *
47  * Since: 2.68
48  */
49 public class StrvBuilder
50 {
51 	/** the main Gtk struct */
52 	protected GStrvBuilder* gStrvBuilder;
53 	protected bool ownedRef;
54 
55 	/** Get the main Gtk struct */
56 	public GStrvBuilder* getStrvBuilderStruct(bool transferOwnership = false)
57 	{
58 		if (transferOwnership)
59 			ownedRef = false;
60 		return gStrvBuilder;
61 	}
62 
63 	/** the main Gtk struct as a void* */
64 	protected void* getStruct()
65 	{
66 		return cast(void*)gStrvBuilder;
67 	}
68 
69 	/**
70 	 * Sets our main struct and passes it to the parent class.
71 	 */
72 	public this (GStrvBuilder* gStrvBuilder, bool ownedRef = false)
73 	{
74 		this.gStrvBuilder = gStrvBuilder;
75 		this.ownedRef = ownedRef;
76 	}
77 
78 	~this ()
79 	{
80 		if ( Linker.isLoaded(LIBRARY_GLIB[0]) && ownedRef )
81 			g_strv_builder_unref(gStrvBuilder);
82 	}
83 
84 
85 	/**
86 	 * Add a string to the end of the array.
87 	 *
88 	 * Since 2.68
89 	 *
90 	 * Params:
91 	 *     value = a string.
92 	 */
93 	public void add(string value)
94 	{
95 		g_strv_builder_add(gStrvBuilder, Str.toStringz(value));
96 	}
97 
98 	/**
99 	 * Appends all the strings in the given vector to the builder.
100 	 *
101 	 * Since 2.70
102 	 *
103 	 * Params:
104 	 *     value = the vector of strings to add
105 	 */
106 	public void addv(string[] value)
107 	{
108 		g_strv_builder_addv(gStrvBuilder, Str.toStringzArray(value));
109 	}
110 
111 	/**
112 	 * Ends the builder process and returns the constructed NULL-terminated string
113 	 * array. The returned value should be freed with g_strfreev() when no longer
114 	 * needed.
115 	 *
116 	 * Returns: the constructed string array.
117 	 *
118 	 *     Since 2.68
119 	 */
120 	public string[] end()
121 	{
122 		auto retStr = g_strv_builder_end(gStrvBuilder);
123 
124 		scope(exit) Str.freeStringArray(retStr);
125 		return Str.toStringArray(retStr);
126 	}
127 
128 	alias doref = ref_;
129 	/**
130 	 * Atomically increments the reference count of @builder by one.
131 	 * This function is thread-safe and may be called from any thread.
132 	 *
133 	 * Returns: The passed in #GStrvBuilder
134 	 *
135 	 * Since: 2.68
136 	 */
137 	public StrvBuilder ref_()
138 	{
139 		auto __p = g_strv_builder_ref(gStrvBuilder);
140 
141 		if(__p is null)
142 		{
143 			return null;
144 		}
145 
146 		return new StrvBuilder(cast(GStrvBuilder*) __p, true);
147 	}
148 
149 	/**
150 	 * Decreases the reference count on @builder.
151 	 *
152 	 * In the event that there are no more references, releases all memory
153 	 * associated with the #GStrvBuilder.
154 	 *
155 	 * Since: 2.68
156 	 */
157 	public void unref()
158 	{
159 		g_strv_builder_unref(gStrvBuilder);
160 	}
161 
162 	/**
163 	 * Creates a new #GStrvBuilder with a reference count of 1.
164 	 * Use g_strv_builder_unref() on the returned value when no longer needed.
165 	 *
166 	 * Returns: the new #GStrvBuilder
167 	 *
168 	 * Since: 2.68
169 	 *
170 	 * Throws: ConstructionException GTK+ fails to create the object.
171 	 */
172 	public this()
173 	{
174 		auto __p = g_strv_builder_new();
175 
176 		if(__p is null)
177 		{
178 			throw new ConstructionException("null returned by new");
179 		}
180 
181 		this(cast(GStrvBuilder*) __p);
182 	}
183 }